package com.ityy.ruiji.controller;

import com.ityy.ruiji.common.R;
import com.ityy.ruiji.entity.Orders;
import com.ityy.ruiji.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 下单
     * @param orders
     * @param httpSession
     * @return
     */
    @PostMapping("submit")
    public R submit(@RequestBody Orders orders, HttpSession httpSession){
        Long user = (Long) httpSession.getAttribute("user");
        orders.setUserId(user);
        R save = orderService.save(orders);
        return save;
    }

    @GetMapping("/userPage")
    public R findAll(Integer page , Integer pageSize){
       R pages = orderService.findAll(page,pageSize);
       return pages;
    }
}
